package lc.数学问题;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/11/3
 */
public class 剑指Offer66_构建乘积数组 {

    public int[] constructArr(int[] a) {

        int[] A = new int[a.length]; // 0 - i - 1 的乘积
        int[] B = new int[a.length]; // i - n - 1 的乘积
        int ans1 = 1;
        int ans2 = 1;
        for (int i = 0, j = a.length - 1; i < a.length; i++,j--) {
            A[i] = ans1;
            ans1 *= a[i];

            B[j] = ans2;
            ans2 *= a[j];
        }
        int[] b = new int[a.length];
        for (int i = 0; i < a.length; i++) {
            b[i] = A[i] * B[i];
        }
        return b;


    }
}
